from typing import List
import random


def func(nums: List, n: int):
    result = []
    prefix = []
    prefix.append(nums[0])
    for i in range(1, len(nums)):
        prefix.append(prefix[-1]+nums[i])
    for _ in range(n):
        x = random.randint(1, prefix[-1])
        for j in range(len(prefix)):
            if x <= prefix[j]:
                result.append(j)
                break
    return result


if __name__ == '__main__':
    t = [2,300,300,2]
    print(func(t, 10))
